package com.we823.cms.controller.manage.ex;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.cms.common.WebConstants;
import com.we823.cms.common.utils.RequestUtil;
import com.we823.cms.common.web.Oper;
import com.we823.cms.controller.manage.AbstractSimpleManageController;
import com.we823.cms.model.extension.CaseCategory;
import com.we823.cms.repository.service.extension.CaseCategoryService;

@Controller
@RequestMapping(WebConstants.MANAGE_URL+"/case_category")
public class CaseCategoryManageController extends
		AbstractSimpleManageController<CaseCategory, Integer> {

	private String baseUrl = WebConstants.MANAGE_URL+"/case_category/";
	
	private CaseCategoryService caseCategoryService;
	
	@Autowired
	public CaseCategoryManageController(CaseCategoryService caseCategoryService) {
		super(caseCategoryService);
		this.caseCategoryService=caseCategoryService;
		super.baseUrl=baseUrl;
	}

	@Override
	public PageInfo<CaseCategory> getData(PageRequest pageRequest,
										  HttpServletRequest request, Model model, boolean pageable) {
		PageInfo<CaseCategory> caseCategoryPage ;
		if (pageable) {
			caseCategoryPage = caseCategoryService.findAll(pageRequest);
		}else {
			caseCategoryPage = new PageInfo<>(caseCategoryService.findAll());
		}
		return caseCategoryPage;
	}

	@Override
	public CaseCategory getEntity(HttpServletRequest request, Integer id,Oper oper) {
		CaseCategory caseCategoryModel = new CaseCategory();
		String name = RequestUtil.getValueByName(request, "name");
		int orderid = RequestUtil.getValueByName(request, "orderid", 0);
		caseCategoryModel.setName(name);
		caseCategoryModel.setOrderid(orderid);
		if (id!=null && id>0) {
			caseCategoryModel.setId(id);
		}
		return caseCategoryModel;
	}

	@Override
	public void setIndetity() {
		setResourceIdentity("ex:case_category");
	}

}
